import * as type from '../mutation-type'

const initState = {
  me: {
    id: null,
    name: null,
    token: null,
    type: null,
  },
  user: {
    counts: {},
  },
  users: [],
  result: [],
}

const state = _.cloneDeep(initState)

const mutations = {
  [type.LOG_IN] (state, value) {
    state.me = value
  },
  [type.LOG_OUT] (state) {
    state.me = initState.me
  },
  [type.SEARCH_USER] (state, value) {
    state.result = value
  },
  [type.GET_USERS] (state, value, concat) {
    if (concat) {
      state.users.push(...value)
    } else {
      state.users = value
    }
  },
  [type.GET_USER] (state, value) {
    state.user = value
  },
}

export default {
  state,
  mutations
}
